import {defineStore} from "pinia";
import {getDepartmentList} from "@/api/department";
import type {IDepartmentInfo} from "@/api/department/type.ts";
import {getOptions, type TOptions} from "@/utils";

type TState = {
    departmentList:IDepartmentInfo[]
}
const useDepartmentStore = defineStore("Department",{
    state():TState{
        return {
            departmentList:[]
        }
    },
    actions:{
        async getDepartmentListAsync(){
            const result = await getDepartmentList();
            this.departmentList = result.data;
        }
    },
    getters:{
        cascaderOptions():TOptions[]{
            return getOptions<IDepartmentInfo>(this.departmentList);
        }
    }
});
export default useDepartmentStore;
